import random


print('----------------------猜字游戏----------------------')
count = 3
guess_number = random.randint(1, 20)
while True:
    print('猜一猜,你有{}次机会。'.format(count))
    tmp = input('猜一个我心里想的数字:')
    print('----------------------hello--------------------------')
    try:
        guess = int(tmp)
    except ValueError as err:
        print('请输入一个正整数,错误提示({})'.format(err))
        continue
    count -= 1
    if guess == guess_number:
        print('太棒了！{}次就猜对了,游戏结束！'.format(3-count))
        break
    elif guess > guess_number:
        if guess > 20:
            print('请输入0-20的数:')
            count += 1
            continue
        print('=======太大了！=========')
    else:
        if guess < 0:
            print('请输入0-20的数:')
            count += 1
            continue
        print('==太小了！==')

    if(count <= 0):
        print('你已经猜了{}次,机会用完了,游戏结束！'.format(3-count))
        break
